﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Wq.Extensions;
using Wq.Extensions.Common;
using Wq.Model;

namespace Wq.Framework
{
    [ApiController]
    public class BaseController : ControllerBase
    {


        protected IActionResult SuccessResult(object data = null, int? Count = null) =>
          Ok(new MessageModel { Success = true, Data = data, Count = Count });

        /// <summary>
        /// 返回成功结果数据
        /// </summary>
        protected IActionResult SuccessResult(MessageModel model) =>
            Ok(new MessageModel { Success = model.Success, Data = model.Data, Count = model.Count, Msg = model.Msg });

        /// <summary>
        /// 获取服务
        /// </summary>
        protected TService Resolve<TService>() =>
             Request.HttpContext.RequestServices.GetService<TService>();


        /// <summary>
        /// 返回Excel文件结果
        /// </summary>
        protected IActionResult ExcelResult(string filename, MemoryStream stream) =>
            File(stream, ExcelHelper.ContentType, filename);
    }
}
